package com.chey.utils;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author JanYao
 * @version 0.1
 */
@Slf4j
public class XmlUtils {
    public static String directory= null;
    public static <T> T getMsg(File file, Class<T> t) {
        T msg = null;
        try {
            FileInputStream input = new FileInputStream("D:\\files\\"+directory +"\\"+ file.getName());
            JacksonXmlModule module = new JacksonXmlModule();
            XmlMapper mapper = new XmlMapper(module);
            msg = mapper.readValue(input, t);
        } catch (IOException e) {
            log.info("解析xml文件失败");
            e.printStackTrace();
        }
        return msg;
    }



}
